package thread;

/**
 * 解释:StringBuilder和StringBuffer的区别
 */
public class SyncAPIDemo1 {
    public static void main(String[] args) {
        //
        StringBuilder sb=new StringBuilder();
        //StringBuffer sb=new StringBuffer();
        Thread t1=new Thread(){
            public void run(){
                for(int i=0;i<1000;i++){
                    sb.append("a");
                }
            }
        };

        Thread t2=new Thread(){
            public void run(){
                for(int i=0;i<1000;i++){
                    sb.append("b");
                }
            }
        };

        t1.start();
        t2.start();

        //等线程完成
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {

        }
        System.out.println(sb.length());

    }
}
